// Copyright 2015 Silicon Laboratories, Inc.

var Constants = {
  // Device Constants
  DEVICE_ID_ON_OFF_SWITCH: 0x0000,
  DEVICE_ID_LEVEL_CONTROL_SWITCH: 0x0001,
  DEVICE_ID_COLOR_DIMMER_SWITCH: 0x0105,
  DEVICE_ID_ON_OFF_LIGHT: 0x0100,
  DEVICE_ID_DIMMABLE_LIGHT: 0x0101,
  DEVICE_ID_COLOR_DIMMABLE_LIGHT: 0x0102,
  DEVICE_ID_HA_ON_OFF_LIGHT: 0x0103,
  DEVICE_ID_EXTENDED_COLOR_LIGHT: 0x0210,
  DEVICE_ID_COLOR_TEMPERATURE_LIGHT: 0x0220,
  DEVICE_TYPE_SENSOR: 0x0302,
  DEVICE_TYPE_CONTACT_SENSOR: 0x0402,
  DEVICE_TYPE_SMART_PLUG: 0x0051,
  DEVICE_TYPE_OCCUPANCY_SENSOR: 0x0107,

  // Device Type Table
  NON_SLEEPY_DEVICE_TYPE_TABLE: {},

  // Decisive Cluster # For In or Out
  IN_OUT_DECISION_CLUSTER: 0x0400,
  // ZigBee On/off Cluster
  ON_OFF_CLUSTER: 0x0006,
  // ZigBee Color-Control Cluster
  COLOR_CONTROL_CLUSTER: 0x0300,
  // ZigBee Level-Control Cluster
  LEVEL_CONTROL_CLUSTER: 0x0008,
  // ZigBee Identify Cluster
  IDENTIFY_CLUSTER: 0x0003,
  IDENTIFY_TIME_ATTRIBUTE: 0x0000,

  // ZigBee Bootloader Cluster
  BOOTLOADER_CLUSTER: 0x0019,
  FIRMWARE_VERSION_ATTRIBUTE: 0x0002,
  FIRMWARE_VERSION_TYPE: 0x0023,
  IMAGE_TYPE_ATTRIBUTE: 0x0008,
  IMAGE_TYPE_TYPE: 0x0021,
  MANUFACTURER_ID_ATTRIBUTE: 0x0007,
  MANUFACTURER_ID_TYPE: 0x0021,

  // ZigBee IAS Zone Cluster
  IAS_ZONE_CLUSTER: 0x0500,
  ZONESTATUS_VAL_ATTRIBUTE: 0x0002,
  ZONESTATUS_VAL_TYPE: 0x0030,

  // ZigBee Temperature Cluster
  TEMPERATURE_CLUSTER: 0x0402,
  TEMPERATURE_VAL_ATTRIBUTE: 0x0000,
  TEMPERATURE_VAL_TYPE: 0x0029,

  // Simple Metering Cluster
  SIMPLE_METERING_CLUSTER: 0x0702,
  SUMMATION_VAL_ATTRIBUTE: 0x0000,
  SUMMATION_VAL_TYPE: 0x0025,
  UNIT_OF_MEASURE_ATTRIBUTE: 0x0300,
  UNIT_OF_MEASURE_TYPE: 0x0030,
  MULTIPLIER_ATTRIBUTE: 0x0301,
  MULTIPLIER_TYPE: 0x0022,
  DIVISOR_ATTRIBUTE: 0x0302,
  DIVISOR_TYPE: 0x0022,
  SUMMATION_FORMATTING_ATTRIBUTE: 0x0303,
  SUMMATION_FORMATTING_TYPE: 0x0018,

  // Illuminance Cluster
  ILLUMINANCE_CLUSTER: 0x0400,
  ILLUMINANCE_VAL_ATTRIBUTE: 0x0000,
  ILLUMINANCE_VAL_TYPE: 0x0021,
  ILLUMINANCE_MINVAL_ATTRIBUTE: 0x0001,
  ILLUMINANCE_MAXVAL_ATTRIBUTE: 0x0002,

  // Humidity Cluster
  HUMIDITY_CLUSTER: 0x0405,
  HUMIDITY_VAL_ATTRIBUTE: 0x0000,
  HUMIDITY_VAL_TYPE: 0x0021,
  HUMIDITY_MINVAL_ATTRIBUTE: 0x0001,
  HUMIDITY_MAXVAL_ATTRIBUTE: 0x0002,

  // Occupancy Sensing Cluster
  OCCUPANCY_CLUSTER: 0x0406,
  OCCUPANCY_VAL_ATTRIBUTE: 0x0000,
  OCCUPANCY_VAL_TYPE: 0x0018,
  OCCUPANCY_SENSOR_TYPE_ATTRIBUTE: 0x0001,
  OCCUPANCY_SENSOR_TYPE_TYPE: 0x0030,

  // Electrical Measurement Cluster
  ELECTRICAL_CLUSTER: 0x0B04,
  RMS_VOLTAGE_VAL_ATTRIBUTE: 0x0505,
  RMS_VOLTAGE_VAL_TYPE: 0x21,
  RMS_CURRENT_VAL_ATTRIBUTE: 0x0508,
  RMS_CURRENT_VAL_TYPE: 0x21,
  ACTIVE_POWER_VAL_ATTRIBUTE: 0x050B,
  ACTIVE_POWER_VAL_TYPE: 0x29,
  ALARMS_MASK_ATTRIBUTE: 0x0800,
  ALARMS_MASK_TYPE: 0x19,
  VOLTAGE_OVERLOAD_ATTRIBUTE: 0x0801,
  VOLTAGE_OVERLOAD_TYPE: 0x29,
  CURRENT_OVERLOAD_ATTRIBUTE: 0x0802,
  CURRENT_OVERLOAD_TYPE: 0x29,
  ACTIVE_POWER_OVERLOAD_ATTRIBUTE: 0x0803,
  ACTIVE_POWER_OVERLOAD_TYPE: 0x29,

  // Diagnostics Cluster
  DIAGNOSTICS_CLUSTER: 0x0B05,
  LQI_VAL_ATTRIBUTE: 0x011C,
  LQI_VAL_TYPE: 0x20,
  RSSI_VAL_ATTRIBUTE: 0x011D,
  RSSI_VAL_TYPE: 0x28,

  // Endpoints
  SELF_ENDPOINT: 0,
  SMART_ENERGY_ENDPOINT: 220,
  GREEN_POWER_ENDPOINT: 242,

  // Commands
  ZONE_STATUS_CHANGE_NOTIFICATION_COMMAND_ID: 0x00,

  // Gateway Transport Defined Node States
  ND_JUST_JOINED:   0x00,
  ND_HAVE_ACTIVE:   0x01,
  ND_HAVE_EP_DESC:  0x02,
  ND_JOINED:        0x10,
  ND_UNRESPONSIVE:  0x11,
  ND_LEAVE_SENT:    0x20,
  ND_LEFT:          0x30,
  ND_UNKNOWN:       0xff,

  // Timing Defines
  SHUTDOWN_TIMER: 1000,
  GATEWAY_HEARTBEAT_FREQUENCY_MS: 5000,
  TEST_MESSAGE_IN_FLIGHT_TIMEOUT: 3000,
  SETUP_ZIGBEE_MS_THROTTLE: 200,
  BIND_POST_DELAY: 200,
  REPORTING_POST_DELAY: 200,
  GATEWAY_PROCESS_WATCHDOG_TIMER: 5000,
  OTA_BLOCKSENT_TIMEOUT: 60000, // 60s

  ZIGBEE_NCP_REQUIRED_VERSION: '5.10.0',
  RSSI_LQI_REQ_DEVICE_LIMIT: 5,
  WILDCARD_DEVICE_EUI: 'FFFFFFFFFFFFFFFF',

  MQTT_PRIVKEY_FILELOCATION: '/certs/client.key',
  MQTT_CERT_FILELOCATION: '/certs/client.crt',
  MQTT_CA_FILELOCATION: '/certs/ca.crt',

  SOCKETS_PRIVKEY_FILELOCATION: '/key.pem',
  SOCKETS_CERT_FILELOCATION: '/fullchain.pem',
  TERMINAL_COMMAND: 'mate-terminal',
  POSTDELAY_KEYWORD: 'postDelayMs',
  POSTDELAYMS_DEFAULT: 100,
  LINKKEY_START_INDEX: 150,
  CENTRALIZED_SECURITY: 1,

  // File Paths
  logPath: '../../../../logs/',
  gatewayTransportLogFilename: 'server.log',
  gatewayLogFilename: 'gateway.log',
  testLogFilename: 'traffictest.log',
  gatewayStore: 'stores/GatewayStores.txt',
  rulesStore: '../stores/CloudRules.txt',
  zb3KeysStore: '../stores/ZB3Keys.txt',
  keyDerivationExec: 'hashing-cli',

  // This path reflects the ZigBee VM's filestructure
  znetOtaDirectory: '../../bin/ota-files',
  otaArchiveSearchingPath: '../../../../../../ota_staging',
  otaArchiveCreationPath: '../../../../ota_staging',
  commandsScriptsPath: '../../../../../../tools',
  staticPath: '../../../../reactui/dist',
  keyDerivationPath: '../../../../../../tools/key-derivation/'
};

Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_ID_ON_OFF_LIGHT] = {};
Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_ID_DIMMABLE_LIGHT] = {};
Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_ID_COLOR_DIMMABLE_LIGHT] = {};
Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_ID_HA_ON_OFF_LIGHT] = {};
Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_ID_EXTENDED_COLOR_LIGHT] = {};
Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_ID_COLOR_TEMPERATURE_LIGHT] = {};
Constants.NON_SLEEPY_DEVICE_TYPE_TABLE[Constants.DEVICE_TYPE_SMART_PLUG] = {};

module.exports = Constants;
